package search.eightpuzzle.astar;

import search.eightpuzzle.model.PuzzleState;

public class ManhattanHeuristic implements Heuristic {
    @Override
    public int estimate(final PuzzleState current, final PuzzleState goal) {
        int distance = 0;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                final int currentVal = current.get(i, j);
                if (currentVal != 0) {
                    distance += Math.abs(i - goal.getRowOf(currentVal));
                    distance += Math.abs(j - goal.getColumnOf(currentVal));
                }
            }
        }
        return distance;
    }

}
